﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//................
using QLKTX1._0.DTO;
using QLKTX1._0.DB;
using System.Data.SqlClient;
using System.Data;
//.................
namespace QLKTX1._0.DAO
{
    class HocVanDAO
    {
        public static List<HocVanDTO> dsHocVan()
        {
            List<HocVanDTO> dsHocVan = new List<HocVanDTO>();

            ConnectDB con = new ConnectDB();
            DataTable dt = con.getDataTable("SELECT * FROM hocVan order by (tenHocVan) asc");


            for (int i = 0; i < dt.Rows.Count; i++)
            {
                HocVanDTO hv = new HocVanDTO();

                hv.MaHocVan = dt.Rows[i]["maHocVan"].ToString();
                hv.TenHocVan = dt.Rows[i]["tenHocVan"].ToString();

                dsHocVan.Add(hv);
               
            }
            return dsHocVan;

        }
        //ham them 
        public static bool themHocVan(HocVanDTO t)
        {
            ConnectDB con = new ConnectDB();
            return con.executeQuery("INSERT INTO hocVan(maHocVan,tenDanToc) VALUES('" + t.MaHocVan  + "','"+ t.TenHocVan +"')");
        }
        //Ham Delete
        public static bool xoaHocVan(HocVanDTO t)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("DELETE FROM hocVan WHERE maHocVan='" + t.MaHocVan + "'");
        }
        //Ham Update
        public static bool capNhatHocVan(HocVanDTO t)
        {
            ConnectDB con = new ConnectDB();

            return con.executeQuery("UPDATE hocVan set tenDanToc='" + t.TenHocVan + "' WHERE maHocVan='" + t.MaHocVan + "'");
        }
    }
}
